/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.miracleteam.miracle.dao.daoImpl;

import com.miracleteam.miracle.dao.SanPhamDAO;
import com.miracleteam.miracle.entities.Sanpham;
import com.miracleteam.miracle.utils.HibernateUtil;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author DangKhoa
 */
public class SanPhamDAOImpl implements SanPhamDAO{
    Logger logger= Logger.getLogger(SanPhamDAOImpl.class);
    
    public Sanpham LaySanPhamChoMatHang(String maMH)
    {
        Sanpham sp = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
        
            String hql = "select mh.sanphamcotaicuahang.sanpham  from Mathangcuagianhang mh where mh.daXoa=0 and mh.maMatHangCuaGianHang=:maMH";
            Query query = session.createQuery(hql);
            query.setString("maMH", maMH);
            Object ob = query.uniqueResult();
            sp =  (Sanpham)ob;
            // gh = (Gianhang) session.get(Gianhang.class, maGianHang);
        } catch (HibernateException e) {
             logger.error(e.getMessage());
             System.out.println(e.getMessage());
        } finally {
            session.close();
        }
        return sp;
    }
}
